//? 1. class
class Sing {
    constructor(name,age) {
        //? 类上的方法instance
        if (!Sing.instance) {
            this.name = name
            this.age = age
            Sing.instance = this
        }
        return Sing.instance
    }
}


//? 2. 闭包

function Single() {
    let instance
    function create() {
        return {}
    }
    return function () {
        if (!instance) {
            instance = create()
        }
        return instance
    }
}

console.log(new Sing("Taobao", 18) === new Sing("Baidu", 15)) // true
const sing = Single()
console.log(sing() === sing()) //? true
